<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		
        <script type="text/javascript">
        	var stockMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.stock');
        	var azMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.accessoryzip');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
			var customer = new i18nMessage('../../servlet/BiFranceCustomerServlet?action=5');
			var ctMaille = new i18nMessage('../../servlet/CodeTableServlet?name=CtMaille');
			var ctZipType = new i18nMessage('../../servlet/CodeTableServlet?name=CtZipType');
			var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
			
			var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/BiAccessoryZipServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			Ext.onReady(function(){
                // create the Data Store
                
                
                store = new Ext.data.Store({
                    url: '../../servlet/StockServlet?action=30',
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [
                    'index', 'reference', 'zipLength', 'ctMaille', 'ctZipType', 'isSpecial', 'comment', 'photoName',
                    'inStock','onTheWayStock','bookedStock','outStock','stock',
                    {
					 	name: 'biFranceCustomer.name',
					 	mapping: 'customerName'
					 }, {
					 	name: 'biFranceCustomer.department',
					 	mapping: 'customerDepartment'
					 }, {
					 	name: 'biFactory.name',
					 	mapping: 'factoryName'
					 },'customerReference','customerColor', 'factoryReference', 'factoryColor', 'ctWeaveType', 'ctZipSize', 'ctSlider', 'ctPuller', 'id']),
                    
                    remoteSort: true
                });
			
				store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'name'},{
						      type: 'string',  
						      dataIndex: 'reference'
					    },{
						      type: 'string',  
						      dataIndex: 'zipLength'
					    },{
						      type: 'list',  
						      dataIndex: 'ctMaille', 
						      options: ctMaille.getCtArray()
					    },{
						      type: 'list',  
						      dataIndex: 'ctZipType', 
						      options: ctZipType.getCtArray()
					    },{
						      type: 'list',  
						      dataIndex: 'isSpecial', 
						      options: ctYesno.getCtArray()
					    },
					    {type: 'string', dataIndex: 'biFranceCustomer.name'},
						{type: 'string', dataIndex: 'biFranceCustomer.department'},
						{type: 'string', dataIndex: 'biFactory.name'}
				]});
				
				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.XTemplate(
			        	'<p><b>' + azMessage.get('ui.accessoryzip.zipweave') + ':</b>&nbsp;&nbsp;{ctWeaveType}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + azMessage.get('ui.accessoryzip.zipsize') + ':</b>&nbsp;&nbsp;{ctZipSize}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + message.get('message.edit.materialtype') + ':</b>&nbsp;&nbsp;{ctMaille}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + azMessage.get('ui.accessoryzip.slider') + ':</b>&nbsp;&nbsp;{ctSlider}</p><br/> ',
			        	'<br/><p><img src="../../_temp/{photoName}" width="150px"/></p>', 
						'<br/><p><b>' + message.get('message.edit.comment') + ':</b> {comment}</p><br/>'
			        )
			    });
			
				grid = new Ext.grid.GridPanel({
                    title: stockMessage.get('ui.stock.zipstock'),
                    store: store,
					stripeRows: true,
					plugins: [expander, filters],
                    height: 560,
                    columns: [expander, {
                        header: message.get('message.list.id'),
                        width: 50,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: azMessage.get('ui.accessoryzip.reference'),
                        dataIndex: 'reference',
                        sortable: true
                    },{
                        header: message.get('message.edit.isspecial'),
                        dataIndex: 'isSpecial',
                        sortable: true
                    },{
                        header: fcMessage.get('ui.francecustomer.name'),
                        dataIndex: 'biFranceCustomer.name',
                        sortable: true
                    },{
                        header: fcMessage.get('ui.francecustomer.department'),
                        dataIndex: 'biFranceCustomer.department',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.customerreference'),
                        dataIndex: 'customerReference',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.customercolor'),
                        dataIndex: 'customerColor',
                        sortable: true
                    },{
                        header: fMessage.get('ui.factory.name'),
                        dataIndex: 'biFactory.name',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.factoryreference'),
                        dataIndex: 'factoryReference',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.factorycolor'),
                        dataIndex: 'factoryColor',
                        sortable: true
                    },{
                        header: message.get('message.edit.materialtype'),
                        dataIndex: 'ctMaille',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.puller'),
                        dataIndex: 'ctPuller',
                        sortable: true
                    },{
                        header: azMessage.get('ui.accessoryzip.length'),
                        dataIndex: 'zipLength',
                        sortable: true
                    },{
                        header: stockMessage.get('ui.stock.instock'),
                        dataIndex: 'inStock',
                        sortable: true,
                        align: 'right',
                        renderer: renderStork
                    },{
                        header: stockMessage.get('ui.stock.onthewaystock'),
                        dataIndex: 'onTheWayStock',
                        sortable: true,
                        align: 'right',
                        renderer: renderStork
                    },{
                        header: stockMessage.get('ui.stock.bookedstock'),
                        dataIndex: 'bookedStock',
                        sortable: true,
                        align: 'right',
                        renderer: renderStork
                    },{
                        header: stockMessage.get('ui.stock.outstock'),
                        dataIndex: 'outStock',
                        sortable: true,
                        align: 'right',
                        renderer: renderStork
                    },{
                        header: message.get('message.edit.stock'),
                        dataIndex: 'stock',
                        align: 'right',
                        renderer: renderStork
                    },{
                        header: message.get('message.edit.adjuststock'),
                        dataIndex: 'id',
                        sortable: false,
                        renderer: function(value, p, record){
                    		return String.format('<a href="accessory_zip_stock_inout_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/lorry.png" title="' + message.get('message.edit.adjuststock') + '" /></a>', record.data.id, Math.floor((record.data.index - 1) / 20) + 1);
                    	}
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'biAccessoryZip',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });			
			});
			
			var renderStork = function(value, p, record){
				if(!value){
               		value = 0;
               	}
               	return render0D(value);
			}
        
        </script>
	</head>
	<body>
	 	<div id="biAccessoryZip">
        </div>
	</body>
</html>